package io.renren.modules.fatboy;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class HtmlUtil {

    public static void main(String[] args) {
        test();
    }

    public static  void test(){
        /**HtmlUnit请求web页面*/
        WebClient wc = new WebClient();
        wc.getOptions().setJavaScriptEnabled(true); //启用JS解释器，默认为true
        wc.getOptions().setCssEnabled(false); //禁用css支持
        wc.getOptions().setThrowExceptionOnScriptError(false); //js运行错误时，是否抛出异常
        wc.getOptions().setTimeout(10000); //设置连接超时时间 ，这里是10S。如果为0，则无限期等待
        System.out.println("Thank God!");

        HtmlPage page = null;
        try {
            page = wc.getPage("https://q.eqxiu.com/s/E6IzG4Wr");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            wc.close();
        }


        String pageXml = page.asXml();//直接将加载完成的页面转换成xml格式的字符串
        System.out.println(pageXml);
//            Document document = Jsoup.parse(pageXml);//获取html文档
//            List<Element> infoListEle = document.getElementById("feedCardContent").getElementsByAttributeValue("class", "feed-card-item");//获取元素节点等
//            infoListEle.forEach(element -> {
//                System.out.println(element.getElementsByTag("h2").first().getElementsByTag("a").text());
//                System.out.println(element.getElementsByTag("h2").first().getElementsByTag("a").attr("href"));
//            });
    }

}
